﻿using System.Text;

namespace System.Security
{
    /// <summary>
    /// 
    /// </summary>
    public class BASE64
    {
        /// <summary>
        /// 
        /// </summary>
        /// <param name="sInputString"></param>
        /// <returns></returns>
        public static string Decode(string sInputString)
        {
            try
            {
                return Encoding.Default.GetString(System.Convert.FromBase64String(sInputString));
            }
            catch (System.ArgumentNullException)
            {
                return string.Empty;
            }
            catch (System.FormatException)
            {
                return string.Empty;
            }
        }

        /// <summary>
        /// 
        /// </summary>
        /// <param name="sInputString"></param>
        /// <returns></returns>
        public static string Encode(string sInputString)
        {
            try
            {
                var bInput = Encoding.Default.GetBytes(sInputString);

                return System.Convert.ToBase64String(bInput, 0, bInput.Length);
            }
            catch (System.ArgumentNullException)
            {
                return string.Empty;
            }
            catch (System.ArgumentOutOfRangeException)
            {
                return string.Empty;
            }
        }
    }
}